package com.tobeface.wechat.message.handler;

import com.tobeface.wechat.message.WeChatMessage;
import com.tobeface.wechat.message.WeChatMessageContext;
import com.tobeface.wechat.message.WeChatMessageHandler;
import com.tobeface.wechat.message.WeChatMessageVerb;

/**
 * @author loudyn
 */
public final class AppAccessMessageHandler implements WeChatMessageHandler {

    @Override
    public boolean isSupport(WeChatMessage message) {
        return message.getVerb() == WeChatMessageVerb.GET;
    }

    @Override
    public void messageReceived(WeChatMessageContext context, WeChatMessage message) {
        String echostr = context.getCredential().getEchostr();
        context.getChannel().write(echostr);
        context.getChannel().flush();
    }

    @Override
    public int getPriority() {
        return HIGH_PRIORITY;
    }

    @Override
    public int compareTo(WeChatMessageHandler other) {
        return other.getPriority() - getPriority();
    }
}
